//
//  UpDataBusCell.m
//  Bus_iPhone
//
//  Created by 修勇 黄 on 12-7-25.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "UpDataBusCell.h"

@implementation UpDataBusCell

@synthesize progressView=_progressView;
@synthesize downLoadBtn=_downLoadBtn;
@synthesize state=_state;

-(void)dealloc{

    [_progressView release];
    [super dealloc];
}

-(void)setState:(UpDataBusState)state{

    if (state==_state) {
        return;
    }
    _state=state;
    
    switch (state) {
        case UpDataBusStateIsDownIng:
        {
            _downLoadBtn.hidden=YES;
            [self.textLabel sizeToFit];
            float tempOr_x=self.textLabel.frame.origin.x+self.textLabel.frame.size.width+5.0f;
            _progressView.frame=CGRectMake(tempOr_x,45.0f/2-_progressView.frame.size.width/2, self.contentView.frame.size.width-tempOr_x-10.0f, _progressView.frame.size.height);
            _progressView.hidden=NO;
        }
            break;
        case UpDataBusStateIsNotDownLoad:
        {
            _progressView.hidden=YES;
            _downLoadBtn.hidden=NO;
        }
            break;
        default:
            break;
    }

}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // In
        _state=UpDataBusStateIsNotDownLoad;
        
        _downLoadBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
        _downLoadBtn.frame=CGRectMake(self.contentView.frame.size.width-80.0f, 45.f/2-30.0f/2, 70.0f, 30.0f);
        [_downLoadBtn setTitle:@"更新数据" forState:UIControlStateNormal];
        _downLoadBtn.titleLabel.font=[UIFont boldSystemFontOfSize:14.0f];
        _downLoadBtn.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
        [self.contentView addSubview:_downLoadBtn];
        
        _progressView=[[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleBar];
        _progressView.frame=CGRectMake(10.0f, 10.0f, 10.0f, 10.0f);
        [self.contentView addSubview:_progressView];
        [_progressView setHidden:YES];
        
        self.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    return self;
}

-(UILabel *)textLabel{

    UILabel *label=[super textLabel];
    [self.contentView bringSubviewToFront:_downLoadBtn];
    [self.contentView bringSubviewToFront:_progressView];
    return label;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
